package com.nuorui.module.supper.dict.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuorui.common.constant.AdminSwaggerTagConst;
import com.nuorui.common.core.domain.ResponseDTO;
import com.nuorui.common.core.domain.ValidateList;
import com.nuorui.module.supper.dict.domain.form.*;
import com.nuorui.module.supper.dict.domain.vo.DictDataVO;
import com.nuorui.module.supper.dict.domain.vo.DictVO;
import com.nuorui.module.supper.dict.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 数据字典 Controller
 *
 * @Author 1024创新实验室-主任-卓大
 * @Date 2025-03-25 22:25:04
 * @Wechat zhuoda1024
 * @Email lab1024@163.com
 * @Copyright <a href="https://1024lab.net">1024创新实验室</a>
 */
@RestController
@Api(tags = AdminSwaggerTagConst.Support.DICT)
public class AdminDictController {

    @Resource
    private DictService dictService;

    @GetMapping("/dict")
    @ApiOperation(value = "字典列表", notes = "字典列表")
    public ResponseDTO<List<DictVO>> getDictList(DictQueryForm dictQueryForm) {
        return ResponseDTO.ok(dictService.getDictList(dictQueryForm));
    }

    @GetMapping("/dict/page")
    @ApiOperation(value = "字典分页", notes = "字典分页")
    public ResponseDTO queryPage(Page page, @Valid DictQueryForm queryForm) {
        return ResponseDTO.ok(dictService.getDictPage(page, queryForm));
    }

    @PostMapping("/dict")
    @ApiOperation(value = "新增字典", notes = "新增字典")
    public ResponseDTO saveDict(@RequestBody @Valid DictForm dictForm) {
        return dictService.saveDict(dictForm);
    }

    @PutMapping("/dict/{dictId}")
    @ApiOperation(value = "更新字典", notes = "更新字典")
    public ResponseDTO updateDict(@PathVariable("dictId") Long dictId, @RequestBody @Valid DictForm dictForm) {
        return dictService.updateDict(dictId, dictForm);
    }

    @PatchMapping("/dict/{dictId}/disabled")
    @ApiOperation(value = "启用/禁用", notes = "启用/禁用")
    public ResponseDTO updateDisabled(@PathVariable Long dictId) {
        return dictService.updateDisabled(dictId);
    }

    @DeleteMapping("/dict")
    @ApiOperation(value = "批量删除", notes = "批量删除")
    public ResponseDTO batchDelete(@RequestBody ValidateList<Long> idList) {
        return dictService.batchDelete(idList);
    }

    @DeleteMapping("/dict/{dictId}")
    @ApiOperation(value = "单个删除", notes = "单个删除")
    public ResponseDTO<String> delete(@PathVariable Long dictId) {
        return dictService.deleteDict(dictId);
    }


    // -------------------  字典数据 -------------------

    @GetMapping("/dict/data")
    @ApiOperation(value = "字典项列表", notes = "字典项列表")
    public ResponseDTO<List<DictDataVO>> getDictDataList() {
        return ResponseDTO.ok(dictService.getDictDataList());
    }

    @GetMapping("/dict/{dictId}/data")
    @ApiOperation(value = "根据字典ID获取字典项列表", notes = "根据字典ID获取字典项列表")
    public ResponseDTO getByDictId(@PathVariable Long dictId) {
        return ResponseDTO.ok(dictService.getByDictId(dictId));
    }


    @PostMapping("/dict/data")
    @ApiOperation(value = "新增字典项", notes = "新增字典项")
    public ResponseDTO<String> saveDictData(@RequestBody @Valid DictDataForm dataForm) {
        return dictService.saveDictData(dataForm);
    }

    @PutMapping("/dict/data/{dictDataId}")
    @ApiOperation(value = "更新字典项", notes = "更新字典项")
    public ResponseDTO<String> updateDictData(@PathVariable("dictDataId") Long dictDataId, @RequestBody @Valid DictDataUpdateForm updateForm) {
        return dictService.updateDictData(dictDataId, updateForm);
    }

    @DeleteMapping("/dict/data/batchDelete")
    @ApiOperation(value = "批量删除字典项", notes = "批量删除字典项")
    public ResponseDTO<String> batchDeleteDictData(@RequestBody ValidateList<Long> idList) {
        return dictService.batchDeleteDictData(idList);
    }

    @DeleteMapping("/dict/data/{dictDataId}")
    @ApiOperation(value = "删除字典项", notes = "删除字典项")
    public ResponseDTO<String> deleteDictData(@PathVariable Long dictDataId) {
        return dictService.deleteDictData(dictDataId);
    }
}
